package com.tarim.wheat.service.impl;

import com.tarim.wheat.mapper.InformationMapper;
import com.tarim.wheat.model.Information;
import com.tarim.wheat.service.InformationService;
import com.tarim.wheat.vo.Criteria;
import com.tarim.wheat.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    InformationMapper informationMapper;

    @Override
    public Information selectByPrimaryKey(Long id) {
        return informationMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageBean selectByCondition(Criteria criteria, PageBean pageBean) {
        criteria.addExtField("pageIndex", (pageBean.getPageIndex() - 1 ) * pageBean.getPageSize());
        criteria.addExtField("pageSize", pageBean.getPageSize());
        Long count = informationMapper.selectByConditionCount(criteria);
        List<Information> list = informationMapper.selectByCondition(criteria);
        pageBean.setTotalCount(count);
        pageBean.setResultList(list);
        return pageBean;
    }

    @Override
    public int updateForDelete(Long id) {
        return informationMapper.updateForDelete(id);
    }

    @Override
    public int insert(Information information) {
        return informationMapper.insert(information);
    }
}
